//
//  FMDBManagerQueue.swift
//  FMDBDemo
//
//  Created by chenxinju on 16/5/19.
//  Copyright © 2016年 Innovation. All rights reserved.
//

import UIKit
import FMDB

class FMDBManagerQueue {
  
    //单例
    static let shareInstance: FMDBManagerQueue = FMDBManagerQueue()

    let queue: FMDatabaseQueue
    
    
    private init() {
    let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).last! as NSString
        
    let dbPath = path.stringByAppendingPathComponent("demo1")
        
    //创建数据库
    queue = FMDatabaseQueue(path: dbPath)
    //不需要手动打开数据库
        
        //创建表格
        createTabel()
    }
    
    
    private  func createTabel() {
     let sql = "CREATE TABLE IF NOT EXISTS 'T_Person' ('person_id' integer NOT NULL PRIMARY KEY AUTOINCREMENT,'name' tet,'score' integer,'sex' integer)"
        
     //执行sql语句
    queue.inDatabase { (db) -> Void in
        db.executeStatements(sql)
        }
    }
}
